package com.aiyige.page.publish.selectsuitablepeople.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.publish.selectsuitablepeople.model.SelectSuitablePeopleItem;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2017/11/9.
 */

public class SelectSuitablePeopleAdapter extends BaseQuickAdapter<SelectSuitablePeopleItem, SelectSuitablePeopleAdapter.ViewHolder> {


    public SelectSuitablePeopleAdapter() {
        super(R.layout.select_suitable_people_item, new LinkedList<SelectSuitablePeopleItem>());
    }

    @Override
    protected void convert(ViewHolder helper, SelectSuitablePeopleItem item) {
        helper.bindData(item);
    }


    public class ViewHolder extends BaseViewHolder {
        @BindView(R.id.titleTv)
        TextView titleTv;
        @BindView(R.id.addIv)
        ImageView addIv;
        @BindView(R.id.containerLayout)
        View containerLayout;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(SelectSuitablePeopleItem item) {
            switch (item.getType()) {
                case SelectSuitablePeopleItem.TYPE_ADD: {
                    titleTv.setVisibility(View.GONE);
                    addIv.setVisibility(View.VISIBLE);
                    containerLayout.setBackgroundResource(R.drawable.course_type_add_bg);
                    break;
                }
                case SelectSuitablePeopleItem.TYPE_NORMAL: {
                    addIv.setVisibility(View.GONE);
                    titleTv.setVisibility(View.VISIBLE);
                    titleTv.setText(item.getTitle());
                    containerLayout.setBackgroundResource(R.drawable.learn_target_item_bg);
                    titleTv.setSelected(item.isSelected());
                    containerLayout.setSelected(item.isSelected());
                    break;
                }
            }
        }
    }
}
